'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  const { router, controller } = app;
  const studentUrl = '/api/student'
  const scoreUrl = '/api/score'

  // 单独注册中间件在路由上使用
  const auth = app.middleware.auth()

  router.get('/', controller.home.index);

  // student路由配置
  // router.get(`${studentUrl}/`, controller.student.index)
  router.post(`${studentUrl}/register`, controller.student.register)
  router.post(`${studentUrl}/login`, controller.student.login)
  router.get(`${studentUrl}/page`, controller.student.findByStuId)

  // score成绩单管理配置
  router.post(`${scoreUrl}/add`, auth, controller.score.add)
  router.post(`${scoreUrl}/update`, auth, controller.score.update)
  router.get(`${scoreUrl}/delete/:stuId`, auth, controller.score.delete)
  router.get(`${scoreUrl}/search`, controller.score.search)
  router.get(`${scoreUrl}/page`, controller.score.page)

  router.get('/api/grade', controller.score.findGrade)

  // 动态路由注册
  // router.post('/api/:type/register', controller.student.test)
};
